package com.budwk.app.sqfw.annotation;

import java.lang.reflect.Field;

/**
 * @program: wk-mini
 * @description: 对象属性值注解处理器
 * @author: LJT
 * @create: 2023-11-21 09:14
 **/
public class FieldValueAnnotationProcessor {
    public static void process(Object obj) {
        for (Field field : obj.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(ProcessFieldValue.class)) {
                ProcessFieldValue annotation = field.getAnnotation(ProcessFieldValue.class);
                try {
                    field.setAccessible(true);
                    String value = (String) field.get(obj);
                    if (value != null) {
                        field.set(obj, value.replaceAll("\\s", "")
                                .replaceAll("\\n", "")
                                .replaceAll("\\r", "")); // 删除所有空格、回车、换行
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
